package com.ch.szh.util;

import java.util.*;

public class ComUtil {
    public  static List converToLowerCaseKey(List<Map<String,Object>> list){
        List<Map<String,Object>> _list=new ArrayList<>();
        for (Map<String, Object> stringObjectMap : list) {
            Map<String,Object> reusltMap= new HashMap<>();
            Set<String> keySet = stringObjectMap.keySet();
            for (String key : keySet) {
                 String newKey = key.toLowerCase();
                 reusltMap.put(newKey, stringObjectMap.get(key));
            }
            _list.add(reusltMap);
        }
        return  _list;
    }

    public static String EncryptStrt(String Src){
        String Key = "CHPS.V1";
        int  KeyLen = Key.length();
        int  KeyPos = -1;
        int Range = 256;
        int SrcAsc = 0;
        Random x = new Random();
        Integer offset = x.nextInt(Range);
        String dest = String.format("%02x", offset).toUpperCase();

        for(int SrcPos = 0; SrcPos < Src.length(); SrcPos++)
        {
            SrcAsc = ((int)(Src.charAt(SrcPos)) + offset) % 255;

            if (KeyPos < KeyLen - 1)
                KeyPos = KeyPos + 1;
            else
                KeyPos = 0;

            SrcAsc = SrcAsc ^ (int)(Key.charAt(KeyPos));
            dest = dest + String.format("%02x", SrcAsc).toUpperCase();      //       Integer.toHexString(SrcAsc).toUpperCase();
            offset = SrcAsc;

        }

        return dest;
    }
}
